﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JScriptSuite.Html;

namespace JScriptSuite.QA.Lib.Html
{
    class TableTests
    {
        internal static JResultItem AllTests()
        {
            HtmlTable table = (HtmlTable)HtmlDocument.Current.CreateElement("TABLE");
            return JResultItem.CreateInstance("TableTests")
                .Push(HeaderTests(table))
                .Push(SectionTests(table))
                .Push(FooterTests(table))
                .Push(BodiesTest(table));
        }

        static JResultItem HeaderTests(HtmlTable table)
        {
            JResultItem resultItem = JResultItem.CreateInstance("HeaderTests");
            resultItem.Push(table.Footer == null);
            HtmlTableSection section = table.CreateFooter();
            resultItem.Push(table.Footer != null);
            return resultItem.Push(SectionTests(section));
        }

        static JResultItem FooterTests(HtmlTable table)
        {
            JResultItem resultItem = JResultItem.CreateInstance("FooterTests");
            resultItem.Push(table.Footer == null);
            HtmlTableSection section = table.CreateFooter();
            resultItem.Push(table.Footer != null);
            return resultItem.Push(SectionTests(section));
        }

        static JResultItem SectionTests(HtmlTableSection section)
        {
            JResultItem resultItem = JResultItem.CreateInstance("SectionTests");
            resultItem.Push(section.TagName);
            for (int i = 0; i < 3; i++)
            {
                section.InsertRow(i);
            }
            resultItem.Push(section.InnerHtml);
            return resultItem;
        }

        static JResultItem BodiesTest(HtmlTable table)
        {
            JResultItem resultItem = JResultItem.CreateInstance("BodiesTests");
            for (int i = 0; i < 3; i++)
            {
                HtmlTableSection section = (HtmlTableSection)table.OwnerDocument.CreateElement("TBODY");
                table.AppendChild(section);
                resultItem.Push(SectionTests(section));
            }

            resultItem.Push(table.Bodies.Length);
            return resultItem;
        }
    }
}
